<template>
  <div>
    <div class="login_box">
      <!-- 头像区域 -->
      <div class="avarar_box">
        <img class="logo" src="@/assets/img/logo.png" />
      </div>
      <!-- 登录表单区域 -->
      <el-form
        :model="loginForm"
        :rules="rules"
        ref="loginFormRef"
        label-width="0"
        class="login_form"
      >
        <!-- 用户名 -->
        <el-form-item prop="username" label="">
          <el-input
            v-model="loginForm.username"
            prefix-icon="el-icon-mobile-phone"
            placeholder="请输入用户名"
          ></el-input>
        </el-form-item>
        <!-- 密码 -->
        <el-form-item prop="password" label="">
          <el-input
            v-model="loginForm.password"
            prefix-icon="el-icon-lock"
            placeholder="请输入密码"
            show-password
          ></el-input>
        </el-form-item>
        <el-form-item class="btns">
          <el-button class="button login" type="primary" @click="login"
            >登录</el-button
          >
          <el-button class="button reset" type="info" @click="resetFrom"
            >重置</el-button
          >
        </el-form-item>
        <div class="goRegister" @click="join">注册账号</div>
      </el-form>
    </div>
  </div>
</template>

<script>
// import mapMutations from 'vuex'
export default {
  data() {
    return {
      loginForm: {
        username: '',
        password: ''
      },
      /* 表单验证规则 可根据需求自行添加/修改*/
      rules: {
        username: [
          {
            required: true,
            pattern: /^1[345678]\d{9}$/,
            message: '请输入正确的手机号码',
            trigger: 'blur'
          }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { min: 6, max: 15, message: '长度在 6 到 15 个字符', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    // ...mapMutations(['login', 'logout']),
    login() {
      // 登录事件 可根据接口/需求自行修改调试
      this.$refs.loginFormRef.validate(valid => { // 验证表单
        if (!valid) return
        /* your code*/
        this.$router.push('/bookshelf') // 测试使用  直接跳转书架
      })
    },
    resetFrom() {
      // 重置登录表单
      this.$refs.loginFormRef.resetFields()
    },
    join() {
      // 未注册 点击跳转注册页面
      this.$router.push('/register')
    }
  }
}
</script>

<style lang="less" scoped>
.loginWrap {
  width: 2rem;
  height: 3rem;
  background: rgba(0, 0, 0, 0.6);
  margin: 0 auto;
}
.login_box {
  width: 450px;
  // height: 300px;
  background-color: #fff;
  border-radius: 3px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -71%);
  .avarar_box {
    width: 256px;
    height: 256px;
    // border: 1px solid #eee;
    // border-radius: 50%;
    padding: 10px;
    // box-shadow: 0 0 10px #ddd;
    margin: 0 auto;
    margin-bottom: 20px;
    // position: absolute;
    // left: 50%;
    // transform: translate(-50%, -50%);
    background-color: #fff;
    .logo {
      display: block;
      width: 100%;
      height: 100%;
      // border-radius: 50%;
      background-color: #eee;
    }
  }
}
.btns {
   width: 300px;
   margin: 0 auto;
  .button {
    width:100%;
    height: 45px;
    border-radius: 49px;
    margin: 0;
    border: none;
  }
  .login {
    background-color: #c70101;
    margin: 20px 0;
    &:hover{
        background-color: #c70101;
    }
  }
  .reset {
    background-color: #999999;
    &:hover{
        background-color: #999999;
    }
  }
}
.login_form {
  width: 100%;
  // position: absolute;
  // bottom: 0;
  padding: 0 20px;
  box-sizing: border-box;
}
.goRegister{
	width: 100%;
	height: 30px;
	font-family: SourceHanSansSC-Regular;
	font-size: 14px;
	font-weight: normal;
	font-stretch: normal;
	line-height: 30px;
	letter-spacing: 0px;
  color: #999999;
  text-align: center;
  margin-top: 65px;
  cursor: pointer;
}
@media screen and (max-width: 768px) {
  .login_box {
    width: 100%;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    .avarar_box {
      width: 100px;
      height: 100px;
    }
  }

}
</style>
